#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,m;
    char aa[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    string s;
    cin>>x>>m;
    while(x!=0){
        s+=aa[x%m];
        x=x/m;
    }
    reverse(s.begin(), s.end());
    cout<<s;
    return 0;
}
